package eg.backend.domain;

import javax.persistence.Entity;
import javax.persistence.Id;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

@Entity
public class GlobalTag {
	@Id
	private String name;
	
	private int usedTimes = 1;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getUsedTimes() {
		return usedTimes;
	}

	public void setUsedTimes(Integer usedTimes) {
		this.usedTimes = usedTimes;
	}

	public void incrementUsedTimes() {
		this.usedTimes++;
	}
	
	public void decreaseUsedTimes() {
		this.usedTimes--;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!this.getClass().isInstance(obj)) {
			return false;
		}

		GlobalTag tag = (GlobalTag) obj;
		return new EqualsBuilder().append(this.getName(), tag.getName()).isEquals();	
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.getName()).toHashCode();
	}	
	
}
